@echo off
del app_dfu_package.zip /Q >NUL 2>NUL
del all_dfu_package.zip /Q >NUL 2>NUL
call build.bat
del bootloader_settings.hex /Q >NUL 2>NUL
echo.

set m_sd_req_TEXT=

set m_sd_filename=
for %%i in (copy_sd/*.hex) do (
set m_sd_filename=%%i
goto Out0_Sd_Filename
)
:Out0_Sd_Filename

if "%m_sd_filename%" == "" goto Condition_Error
if "%m_sd_filename%" == "s132_nrf52_5.0.0_softdevice.hex" (
set m_sd_req_TEXT=0x9D
goto Condition_Okay
)
if "%m_sd_filename%" == "s132_nrf52_5.1.0_softdevice.hex" (
set m_sd_req_TEXT=0xA5
goto Condition_Okay
)
goto Condition_Error
:Condition_Okay
echo --sd-req %m_sd_req_TEXT%

if "%1"=="a" goto Package_All
if "%1"=="A" goto Package_All

echo start package * APP only ...
..\..\..\tools\nrfutil pkg generate --hw-version 52 --sd-req %m_sd_req_TEXT% --application-version 1 --application App.hex --key-file create_keys\private.key app_dfu_package.zip
if %errorlevel% neq 0 goto Package_Error
..\..\..\tools\nrfutil pkg display app_dfu_package.zip
goto Package_Okay

:Package_All
echo start package * BL + SD + APP ...
..\..\..\tools\nrfutil pkg generate --hw-version 52 --sd-req %m_sd_req_TEXT% --sd-id %m_sd_req_TEXT% --application-version 1 --bootloader-version 1 --bootloader BL.hex --application App.hex --softdevice copy_sd\%m_sd_filename% --key-file create_keys\private.key all_dfu_package.zip
if %errorlevel% neq 0 goto Package_Error
..\..\..\tools\nrfutil pkg display all_dfu_package.zip
goto Package_Okay

:Condition_Error
echo The softdevice is not supported.
echo Please check it first.
echo.
pause
goto Package_Okay

:Package_Error
echo A package error occurred.
echo Please check it first.
echo.
pause
goto Package_Okay

:Package_Okay
